
$(function() {
	getProjectVersionList();
});

function loadProjectVersionCompare() {
	var chk_value =[]; 
	$('input[name="selectArrays"]:checked').each(function(){ 
		chk_value.push($(this).val()); 
	}); 
	if(chk_value.length!=2) {
		alert('项目变更版本对比只能是两个版本之间的对比，请选择！');
	}else {
		location.href='project_version_compare.jsp?versionId1=' + chk_value[0] + "&versionId2=" + chk_value[1];
	}
}

//查询历史版本列表
function getProjectVersionList() {
	var id = $("#id").val();
	$.ajax({
	  url: 'project!getProjectVersionList.action',
	  type: 'post',
	  data: {
	  	"id": id
	  },
	  dataType: 'json',
	  success: function(data) {
		  Interceptor(data);
	  	 $("#name").html(data[0].projectName);
	     // 列表
	     var resultContent = '<tr>'
					          +'<th scope="col">选择</th>'
					          +'<th scope="col">变更日期</th>'
					          +'<th scope="col">变更状态</th>'
					          +'<th scope="col">审核人</th>'
					          +'<th scope="col">审核意见</th>'
					          +'<th scope="col">版本号</th>'
					          +'<th scope="col">操作</th>'
					        +'</tr>';
	     if(data[0].list.length>0) {
	     	if(data[0].list[0].versionStatus=='1') {
		 		$("#pv_btn").show(); //只有上个项目变更审核过了才能重新进行项目变更
		 	}
	     }
	     $(data[0].list).each(function(i) {
	     		var statusStr = '';
	     		var trStr = '';
	     		if(i%2==0) {
	     			trStr = 'class="odd"';
	     		}
	     		if(data[0].list[i].versionStatus=='0') {
	     			statusStr = '待审核';
	     		}else if(data[0].list[i].versionStatus=='1') {
	     			statusStr = '审核通过';
	     		}else if(data[0].list[i].versionStatus=='2') {
	     			statusStr = '审核不通过';
	     		}
	     		var auditUserStr='';
	     		if(data[0].list[i].versionAuditUser!=null) {
	     			auditUserStr = data[0].list[i].versionAuditUser.name;
	     		}
				resultContent += '<tr ' + trStr +  '>'
								+ '<td align="center"><input type="checkbox" name="selectArrays" value="' + data[0].list[i].id + '" id="' + data[0].list[i].id + '_id"></td>'
                            	+ '<td align="center" height="30">' + data[0].list[i].versionTime.substring(0,10) + '</td>'
                                + '<td align="center" style="color: red;">' + statusStr + '</td>'
                                + '<td align="center">' + auditUserStr + '</td>'
                                + '<td align="center">' + data[0].list[i].versionAuditReason+ '</td>'
                                + '<td align="center">Version' + data[0].list[i].versionNumber + '</td>'
                                + '<td align="center"><a href="project_version_find.jsp?id=' + data[0].list[i].id + '">查看版本详情</a></td>'
                                + '</tr>';
		 });
		 
		 
		 if(data[0].list==null || data[0].list=='') {
		 	resultContent += '<tr><td colspan="4" height="30">该项目暂无变更信息！</td></tr>'
		 }
		 $("#mainData").html(resultContent); 
	  }, 
	  error: function() {
		  //
	  }
    });
}
